<!-- 风险对象 -->
<template>
  <div class="dual_prevention_div" v-loading="tableLoading" element-loading-text="数据加载中">
    <div class="dual_prevention_query_div">
      <el-form :model="searchForm" :inline="true" size="small">
        <el-form-item label="" label-width="0">
          <el-input v-model="searchForm.oName" placeholder="请输入风险分析对象" clearable @clear="currentPage = 1;inquiry();"></el-input>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-input v-model="searchForm.hazardCode" placeholder="请输入编码" clearable @clear="currentPage = 1;inquiry();"></el-input>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-select v-model="searchForm.oType" placeholder="请选择分类" clearable @change="currentPage = 1;inquiry();" @clear="currentPage = 1;inquiry();">
            <el-option label="生产装置" value="0" />
            <el-option label="罐区" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-select v-model="searchForm.oIfRisk" placeholder="请选择是否重大危险源" clearable @change="  currentPage = 1;  inquiry(); " 
              @clear="currentPage = 1; inquiry();">
            <el-option label="是" value="0" />
            <el-option label="否" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-input v-model="searchForm.hazardDep" placeholder="请输入责任部门" clearable @clear=" currentPage = 1;  inquiry(); "></el-input>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-button type="success" size="small" @click=" currentPage = 1; inquiry(); ">查询</el-button>
          <el-button type="primary" size="small" @click="handleAdd">添加</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="dual_prevention_table_div">
      <el-table :data="tableData" style="width: 100%" height="100%">
        <el-table-column prop="oName" label="风险分析对象" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="hazardCode" label="编码" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oType" label="分类" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.oType === '0'">生产装置</span>
            <span v-if="scope.row.oType === '1'">罐区</span>
          </template>
        </el-table-column>
        <el-table-column prop="oIfRisk" label="是否重大危险源" align="center">
          <template slot-scope="scope">
            {{ scope.row.oIfRisk === '0' ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column prop="hazardDep" label="责任部门" align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="czHazard" label="操作负责人" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="jsHazard" label="技术负责人" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="zyHazard" label="主要负责人" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="whether" label="是否管控" align="center">
          <template slot-scope="scope">
            {{ scope.row.whether === '0' ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建时间" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="400" fixed="right" align="center">
          <template slot-scope="scope">
            <CustomButton :onClick="() => handleEdit(scope.row)">编辑</CustomButton>
            <CustomButton :onClick="() => handleLook(scope.row)">详情</CustomButton>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="dual_prevention_footer_div" v-show="pageLength * 1 > 0">
      <el-pagination @size-change="handleSizeChange" background @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizes" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="pageLength">
      </el-pagination>
    </div>
    <!-- 添加组件 -->
    <add-device ref="addDevice" @success="inquiry" />
    <!-- 编辑组件 -->
    <edit-device ref="editDevice" @success="inquiry" />
    <!-- 详情组件 -->
    <look-device ref="lookDevice" @success="inquiry" />
  </div>
</template>

<script>
import mixin from '@/mixins/index';
import CustomButton from '@/components/CustomButton/index.vue';
import AddDevice from './components/AddDevice.vue';
import EditDevice from './components/EditDevice.vue';
import LookDevice from './components/LookDevice.vue';
import { useriskObjectApi } from '@/api/riskObjectApi';

export default {
  mixins: [mixin],
  components: {
    CustomButton,
    AddDevice,
    EditDevice,
    LookDevice
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      searchForm: {
        oName: '',
        hazardCode: '',
        oType: '',
        oIfRisk: '',
        hazardDep: ''
      }
    };
  },
  created() {
    this.inquiry();
  },
  methods: {
    inquiry() {
      this.tableLoading = true;
      const params = {
        pageNo: this.currentPage,
        pageSize: this.pageSize,
        ...this.searchForm
      };
      useriskObjectApi()
        .findObject(params)
        .then((resp) => {
          if (resp.code * 1 === 100) {
            this.tableData = resp.info.records;
            this.pageLength = resp.info.total;
          } else {
            this.$message.error(resp.message || '数据请求失败');
          }
          this.tableLoading = false;
        })
        .catch((err) => {
          console.error('查询失败:', err);
          this.$message.error(err.message || '请求发生错误');
          this.tableLoading = false;
        });
    },
    handleAdd() {
      this.$refs.addDevice.show();
    },
    handleEdit(row) {
      this.$refs.editDevice.show(row);
    },
    handleLook(row) {
      this.$refs.lookDevice.show(row);
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/theme/scroll-bar.scss';

.dual_prevention_div {
  // background-color: red;
  // max-height: fit-content;
  height: calc(100vh - 120px);
  display: flex;
  background-color: #ffffff;
  flex-direction: column;
  flex: 1;
  width: 100%;
  border: 1px solid #ebeef5;
  color: #303133;
  padding: 15px;

  .dual_prevention_query_div {
    width: 100%;
  }

  .dual_prevention_table_div {
    flex: 1;
    overflow: hidden;
    width: 100%;

    .el-table {
      flex: 1;
    }

    .el-table__inner-wrapper {
      position: relative;
      display: flex;
      flex-direction: column;
      height: 100%;
      flex-wrap: nowrap;
    }
  }

  .dual_prevention_footer_div {
    margin-top: 15px !important;
    width: 100%;
    height: 24px;
  }
}

.el-scrollbar .el-scrollbar__view .el-select-dropdown__item {
  height: auto;
  // padding: 0  ;/
}
</style>
